package com.xiye.common.controller;

import com.xiye.common.entity.PageData;
import com.xiye.common.util.UuidUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 西野
 * @version V1.0
 * @title BaseController.java
 * @package com.xiye.common.controller
 * @description 父controller
 * @date 2018-07-11
 */
public class BaseController {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    private static final long serialVersionUID = 6357869213649815390L;

    /*
     * @Author 西野
     * @Date 2018-07-23 09:52:05
     * @Description new PageData对象
     * @Param []
     * @Return com.xiye.common.entity.PageData
     */
    public PageData getPageData() {
        return new PageData(this.getRequest());
    }

    /*
     * @Author 西野
     * @Date 2018-07-23 09:52:21
     * @Description 得到request对象
     * @Param []
     * @Return javax.servlet.http.HttpServletRequest
     */
    public HttpServletRequest getRequest() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return request;
    }

    /*
     * @Author 西野
     * @Date 2018-07-23 09:52:31
     * @Description 得到32位的uuid
     * @Param []
     * @Return java.lang.String
     */
    public String get32UUID() {
        return UuidUtil.get32UUID();
    }

    /*
     * @Author 西野
     * @Date 2018-07-23 09:52:41
     * @Description 代码执行前打印日志
     * @Param [logger, interfaceName]
     * @Return void
     */
    public static void logBefore(Logger logger, String interfaceName) {
        logger.info("");
        logger.info("START");
        logger.info(interfaceName);
    }

    /*
     * @Author 西野
     * @Date 2018-07-23 09:52:50
     * @Description 代码执行后打印日志
     * @Param [logger]
     * @Return void
     */
    public static void logAfter(Logger logger) {
        logger.info("END");
        logger.info("");
    }

}
